package com.jiazhong.basic.shuxin.thread;

import lombok.SneakyThrows;

// 后台线程
public class DemoE {

    @SneakyThrows
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                System.out.println(Thread.currentThread().getName() + "正在执行代码");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "在执行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        // 设置t1线程是后台线程
        t1.setDaemon(true);
        t1.start();
        t2.start();
    }
}
